package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.*;
import com.example.demo.service.*;
import com.example.demo.dao.WeifenMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【weifen】的数据库操作Service实现
* @createDate 2023-02-28 15:35:09
*/
@Service
public class WeifenServiceImpl extends ServiceImpl<WeifenMapper, Weifen>
    implements WeifenService{

    @Autowired
    OrdersService ordersService;
    @Autowired
    OrderItemService orderItemService;

    @Autowired
    CustomerService customerService;

    @Autowired
    MallgoodsService mallgoodsService;
    @Override
    public Weifen addOrder(Orders orders) {
        Weifen  weifen = new Weifen();
       QueryWrapper<OrderItem> queryWrapper = new QueryWrapper<>();
       queryWrapper.eq("order_id",orders.getId().toString());
        List<OrderItem> list = orderItemService.list(queryWrapper);
        OrderItem orderItem = list.get(0);
        weifen.setOrderno(orders.getOrderno());


        QueryWrapper<Customer> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("id" ,orders.getUserid());
        List<Customer> list1 = customerService.list(queryWrapper1);
        Customer customer = list1.get(0);
        weifen.setCustomer(customer.getName());
        weifen.setPhone(customer.getPhone());

        QueryWrapper<Mallgoods> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("name",orderItem.getGoodsName());
        List<Mallgoods> list2 = mallgoodsService.list(queryWrapper2);
        Mallgoods mallgoods = list2.get(0);
        weifen.setGoods(mallgoods.getName());
        weifen.setUnit(mallgoods.getUnit());
        weifen.setDanprice(orderItem.getPrice());
        weifen.setNum(orderItem.getNum());
        weifen.setPrice(orders.getTotal());
        weifen.setAddress(customer.getAddress());

return weifen;
    }
}




